package cn.com.dycc.warning_info.info_user.controller;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.com.dycc.common.controller.BaseController;
import cn.com.dycc.util.JsonObjectResult;
import cn.com.dycc.warning_info.info_user.entity.InfoUser;
import cn.com.dycc.warning_info.info_user.param.InfoUserParam;
import cn.com.dycc.warning_info.info_user.service.InfoUserNotFoundException;
import cn.com.dycc.warning_info.info_user.service.InfoUserService;


/**
 * 
 * Description: 提醒通知信息管理控制层
 * Author: Liket
 * Version: 1.0
 * Create Date Time: 2018年11月19日 下午3:54:20.
 * Update Date Time: 
 * @see
 */
@Controller
@RequestMapping("/infoUser")
public class InfoUserController extends BaseController{
	
	@Resource
	private InfoUserService infoUserService;
	
	@RequestMapping("/add.do")
	@ResponseBody
	public JsonObjectResult addInfoUser(HttpServletRequest req,InfoUser infoUser){
		int n = infoUserService.addInfoUser(req, infoUser);
		return new JsonObjectResult(n);
	}
	
	@RequestMapping("/delete.do")
	@ResponseBody
	public JsonObjectResult deleteInfoUser(HttpServletRequest req,String info_id){
		int n = infoUserService.deleteInfoUser(req, info_id);
		return new JsonObjectResult(n);
	}
	
	@RequestMapping("/update.do")
	@ResponseBody
	public JsonObjectResult updateInfoUser(HttpServletRequest req,InfoUser infoUser){
		int n = infoUserService.updateInfoUser(req, infoUser);
		return new JsonObjectResult(n);
	}
	
	@RequestMapping("/find.do")
	@ResponseBody
	public JsonObjectResult findInfoUser(HttpServletRequest req,String info_id){
		InfoUser infoUser = infoUserService.findInfoUserById(req, info_id);
		return new JsonObjectResult(infoUser);
	}
	
	@RequestMapping("/param.do")
	@ResponseBody
	public JsonObjectResult paramInfoUser(HttpServletRequest req,InfoUserParam param){
		List<InfoUser> list = infoUserService.findInfoUserByParam(req,param);
		String count = infoUserService.countInfoUserByParam(req,param);
		return new JsonObjectResult(count,list);
	}
	
	@RequestMapping("/warning.do")
	@ResponseBody
	public JsonObjectResult warningInfoUser(HttpServletRequest req,InfoUserParam param){
		HttpSession session = req.getSession();
		String user_id = (String)session.getAttribute("id");
		param.setUser_id(user_id);
		List<InfoUser> list = infoUserService.findInfoUserByParam(req,param);
		String count = infoUserService.countInfoUserByParam(req,param);
		return new JsonObjectResult(count,list);
	}
	
	@ExceptionHandler(InfoUserNotFoundException.class)
	@ResponseBody
	public JsonObjectResult infoUserException(InfoUserNotFoundException e){
		e.printStackTrace();
		return new JsonObjectResult(1030,e);
	}
}
